//
//  UIImage+Image.m
//  Runtime交换方法
//
//  Created by 周成龙 on 16/7/31.
//  Copyright © 2016年 none. All rights reserved.
//

#import "UIImage+Image.h"

#import <objc/message.h>

@implementation UIImage (Image)

/*
 将 zcl_imageNameMethod 和 imageNamed 交换
 */

+ (void)load
{   
    Method imageNameMethod = class_getClassMethod([UIImage class], @selector(imageNamed:));
    Method zcl_imageNameMethod = class_getClassMethod([UIImage class], @selector(zcl_imageNamed:));
    
    method_exchangeImplementations(imageNameMethod, zcl_imageNameMethod);
}

+ (UIImage *)zcl_imageNamed:(NSString *)imageName
{
    // 1. 加载图片
    UIImage *image = [UIImage zcl_imageNamed:imageName];
    
    // 2. 判断功能
    if (image == nil) {
        NSLog(@"图片为空");
        return nil;
    }
    
    return image;
}

@end
